<!--个人中心页面，展示用户详细信息。-->
<template>
  <Layout>
    <div class="profile-container">
      <el-card shadow="hover" class="profile-card">
        <div class="profile-header">
          <el-avatar :icon="User" class="profile-avatar"></el-avatar>
          <div class="profile-name">
            <h2>{{ userStore.user?.username }}</h2>
            <p>{{ userStore.user?.role === 'admin' ? '管理员' : '普通用户' }}</p>
          </div>
        </div>
        
        <el-divider content-position="left">个人信息</el-divider>
        
        <el-descriptions column="1" border>
          <el-descriptions-item label="用户名">{{ userStore.user?.username }}</el-descriptions-item>
          <el-descriptions-item label="用户ID">{{ userStore.user?.id }}</el-descriptions-item>
          <el-descriptions-item label="角色">{{ userStore.user?.role === 'admin' ? '管理员' : '普通用户' }}</el-descriptions-item>
          <el-descriptions-item label="注册时间">{{ userStore.user?.registerTime || '未知' }}</el-descriptions-item>
          <el-descriptions-item label="最后登录">{{ lastLoginTime }}</el-descriptions-item>
        </el-descriptions>
        
        <div class="profile-actions">
          <el-button type="primary" @click="handleEditProfile">编辑资料</el-button>
          <el-button type="warning" @click="handleChangePassword">修改密码</el-button>
        </div>
      </el-card>
    </div>
  </Layout>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useUserStore } from '../stores/user'
import Layout from '../components/Layout.vue'
import { User } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

// 用户状态
const userStore = useUserStore()

// 最后登录时间
const lastLoginTime = ref('刚刚')

onMounted(() => {
  // 如果没有用户信息，获取一下
  if (userStore.isLoggedIn && !userStore.user) {
    userStore.fetchCurrentUser()
  }
})

// 编辑资料
const handleEditProfile = () => {
  ElMessage.info('编辑资料功能待实现')
}

// 修改密码
const handleChangePassword = () => {
  ElMessage.info('修改密码功能待实现')
}
</script>

<style scoped>
.profile-container {
  max-width: 800px;
  margin: 0 auto;
}

.profile-card {
  padding: 20px;
}

.profile-header {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  font-size: 50px;
  margin-right: 30px;
}

.profile-name h2 {
  margin: 0 0 10px 0;
  color: #1E293B;
}

.profile-name p {
  margin: 0;
  color: #64748B;
  font-size: 14px;
}

.el-descriptions {
  margin-bottom: 30px;
}

.el-descriptions-item__label {
  font-weight: bold;
}

.profile-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
}
</style>
